from pydantic import BaseModel


class ControlStates(BaseModel):
    block_state: bool = False
    artix_state: bool = True
    link_0_state: bool = False
    link_1_state: bool = False
    service_0_state: bool = False
    service_1_state: bool = False
    service_2_state: bool = False
    service_3_state: bool = False
    service_5v_state: bool = False
    link_ad_state: bool = True
    service_0_ad_state: bool = False
    service_1_ad_state: bool = False
    led_0_modem_state: bool = False
    led_1_modem_state: bool = False
    led_2_modem_state: bool = False
    led_3_modem_state: bool = False
    external_sensor_1: bool = False
    external_sensor_2: bool = False
    modem_state: bool = True

    def get(self, name: str) -> bool:
        return getattr(self, name)

    def set(self, name: str, state: bool):
        return setattr(self, name, state)


class ControlStatesInfo(BaseModel):
    class Info(BaseModel):
        address: int = 0x0000_0000
        offset: int = 0x00

    block_state: Info = Info(address=0x83C1_0000, offset=0x00)

    artix_state: Info = Info(address=0x4120_0000, offset=0x00)

    link_0_state: Info = Info(address=0x43C0_0000, offset=0x04)
    link_1_state: Info = Info(address=0x43C0_0000, offset=0x05)

    service_0_state: Info = Info(address=0x43C0_0000, offset=0x07)
    service_1_state: Info = Info(address=0x43C0_0000, offset=0x06)
    service_2_state: Info = Info(address=0x43C0_0000, offset=0x01)
    service_3_state: Info = Info(address=0x43C0_0000, offset=0x00)
    service_5v_state: Info = Info(address=0x43C0_0000, offset=0x03)

    link_ad_state: Info = Info(address=0x43C0_0000, offset=0x0E)
    service_0_ad_state: Info = Info(address=0x43C0_0000, offset=0x0C)
    service_1_ad_state: Info = Info(address=0x43C0_0000, offset=0x0D)

    led_0_modem_state: Info = Info(address=0x43C0_0000, offset=0x08)
    led_1_modem_state: Info = Info(address=0x43C0_0000, offset=0x09)
    led_2_modem_state: Info = Info(address=0x43C0_0000, offset=0x0A)
    led_3_modem_state: Info = Info(address=0x43C0_0000, offset=0x0B)

    external_sensor_1: Info = Info(address=0X43C6_0018, offset=0x00)
    external_sensor_2: Info = Info(address=0X43C6_001C, offset=0x00)

    modem_state: Info = Info(address=0x43C0_0000, offset=0x0F)

    def get(self, name: str) -> Info:
        return getattr(self, name)
